LIBRARY ieee;
USE ieee.std_logic_1164.all;

-- 12 bit look-ahead adder so we can calculate stuff in one cycle
-- Recycled from my old 152 project.

ENTITY CLA12 IS
	PORT( a,b				:IN 	STD_LOGIC_VECTOR(11 DOWNTO 0);
		  output			:OUT	STD_LOGIC_VECTOR(11 DOWNTO 0));
END CLA12;

ARCHITECTURE LogicFunc OF CLA12 IS

SIGNAL cin				: STD_LOGIC;
SIGNAL carries			: STD_LOGIC_VECTOR(11 DOWNTO 0);
SIGNAL outs				: STD_LOGIC_VECTOR(11 DOWNTO 0);

BEGIN

-- HUGE LOGIC STATEMENT!
cin <= '0';
--carries(0)  <= (a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin));
outs(0) <= ((a(0) XOR b(0)) XOR cin);
--carries(1)  <= (a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))));
outs(1) <= ((a(1) XOR b(1)) XOR ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))));
--carries(2)  <= (a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))));
outs(2) <= ((a(2) XOR b(2)) XOR ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))));
--carries(3)  <= (a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))));
outs(3) <= ((a(3) XOR b(3)) XOR ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))));
--carries(4)  <= (a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))));
outs(4) <= ((a(4) XOR b(4)) XOR ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))));
--carries(5)  <= (a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))));
outs(5) <= ((a(5) XOR b(5)) XOR ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))));
--carries(6)  <= (a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))));
outs(6) <= ((a(6) XOR b(6)) XOR ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))));
--carries(7)  <= (a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))));
outs(7) <= ((a(7) XOR b(7)) XOR ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))));
--carries(8)  <= (a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))));
outs(8) <= ((a(8) XOR b(8)) XOR ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))));
--carries(9)  <= (a(9) AND b(9)) OR ((a(9) OR b(9)) AND ((a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))))));
outs(9) <= ((a(9) XOR b(9)) XOR ((a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))))));
--carries(10)  <= (a(10) AND b(10)) OR ((a(10) OR b(10)) AND ((a(9) AND b(9)) OR ((a(9) OR b(9)) AND ((a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))))))));
outs(10) <= ((a(10) XOR b(10)) XOR ((a(9) AND b(9)) OR ((a(9) OR b(9)) AND ((a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))))))));
--carries(11)  <= (a(11) AND b(11)) OR ((a(11) OR b(11)) AND ((a(10) AND b(10)) OR ((a(10) OR b(10)) AND ((a(9) AND b(9)) OR ((a(9) OR b(9)) AND ((a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))))))))));
outs(11) <= ((a(11) XOR b(11)) XOR ((a(10) AND b(10)) OR ((a(10) OR b(10)) AND ((a(9) AND b(9)) OR ((a(9) OR b(9)) AND ((a(8) AND b(8)) OR ((a(8) OR b(8)) AND ((a(7) AND b(7)) OR ((a(7) OR b(7)) AND ((a(6) AND b(6)) OR ((a(6) OR b(6)) AND ((a(5) AND b(5)) OR ((a(5) OR b(5)) AND ((a(4) AND b(4)) OR ((a(4) OR b(4)) AND ((a(3) AND b(3)) OR ((a(3) OR b(3)) AND ((a(2) AND b(2)) OR ((a(2) OR b(2)) AND ((a(1) AND b(1)) OR ((a(1) OR b(1)) AND ((a(0) AND b(0)) OR ((a(0) OR b(0)) AND (cin))))))))))))))))))))))));

output <= outs;

END LogicFunc;